//
//  RepairOrderViewController.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/6/26.
//

import UIKit
import SnapKit
import JXSegmentedView

/// 维修单
class RepairOrderViewController: UIViewController {

  let segmentedView = JXSegmentedView()
  let segmentedDataSource = JXSegmentedTitleDataSource()

  lazy var listContainerView = JXSegmentedListContainerView(dataSource: self)

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

      opacityNavigationBar(color: .designKit.background)

      view.backgroundColor = .designKit.background

      segmentedView.delegate = self
      view.addSubview(segmentedView)

      segmentedDataSource.titles = ["待维修", "已维修", "已转单"]
      segmentedDataSource.isTitleColorGradientEnabled = true
      segmentedView.dataSource = self.segmentedDataSource
      segmentedView.backgroundColor = .designKit.background
      segmentedDataSource.titleSelectedColor = .designKit.accent

      let indicator = JXSegmentedIndicatorLineView()
      indicator.indicatorWidth = 42
      indicator.indicatorColor = .designKit.accent
      segmentedView.indicators = [indicator]

      segmentedView.listContainer = listContainerView
      view.addSubview(listContainerView)

      segmentedView.snp.makeConstraints { make in
        make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
        make.left.right.equalToSuperview()
        make.height.equalTo(36)
      }

      listContainerView.snp.makeConstraints { make in
        make.top.equalTo(segmentedView.snp.bottom)
        make.left.right.equalToSuperview()
        make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
      }
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension RepairOrderViewController: JXSegmentedViewDelegate {
}

extension RepairOrderViewController: JXSegmentedListContainerViewDataSource {

  func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
    return segmentedDataSource.titles.count
  }

  func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {

    let vc = RepairOrderListViewController()
    switch index {
    case 1:
      vc.type = .repaired
    case 2:
      vc.type = .transcription
    default:
      vc.type = .waitingRepair
    }
    return vc
  }
}



